import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { DictEnum } from '@vben/constants';
// import { VbenIcon } from '@vben/icons';
import { getPopupContainer } from '@vben/utils';

// import { Tag } from 'ant-design-vue';
// import { z } from '#/adapter/form';
import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'name',
    label: '任务名称',
  },
  {
    component: 'ExhibitionSelect',
    fieldName: 'exhibitionId',
    label: '所属展会',
  },
  {
    component: 'Select',
    componentProps: {
      getPopupContainer,
      options: getDictOptions(DictEnum.EXHIBITION_NUMBER, true),
    },
    fieldName: 'number',
    label: '届数',
  },
  {
    component: 'Select',
    componentProps: {
      getPopupContainer,
      options: getDictOptions(DictEnum.SMS_TASK_SEND_TYPE, true),
    },
    fieldName: 'sendType',
    label: '发送类型',
  },
  {
    component: 'RangePicker',
    fieldName: 'sendTime',
    label: '发送时间',
  },
  {
    component: 'UserListSelect',
    fieldName: 'createBy',
    label: '创建人',
  },
];

export const columns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 60 },
  {
    title: '任务名称',
    field: 'name',
    width: 230,
  },
  {
    title: '短信主题',
    field: 'smsName',
    minWidth: 200,
  },
  {
    title: '发送类型',
    field: 'sendType',
    width: 120,
    slots: {
      default: ({ row }) => {
        return renderDict(row.sendType, DictEnum.SMS_TASK_SEND_TYPE, true);
      },
    },
  },
  {
    title: '发送时间',
    field: 'sendTime',
    width: 180,
  },
  {
    title: '发送状态',
    field: 'taskStatus',
    width: 120,
    slots: {
      default: ({ row }) => {
        return renderDict(
          row.taskStatus,
          DictEnum.EMAIL_TASK_SEND_STATUS,
          true,
        );
      },
    },
  },
  {
    title: '收件人组',
    field: 'favorites',
    minWidth: 400,
    slots: { default: 'favorites' },
    showOverflow: false,
  },
  {
    title: '发送数量',
    field: 'sendCount',
    width: 250,
    slots: { default: 'sendCount' },
  },
  {
    title: '备注',
    field: 'remark',
    width: 200,
    showOverflow: true,
    visible: false,
  },
  {
    title: '创建人',
    field: 'createByName',
    width: 140,
  },
  {
    title: '创建时间',
    field: 'createTime',
    width: 180,
    visible: false,
  },
  {
    title: '最后更新人',
    field: 'updateByName',
    width: 140,
    visible: false,
  },
  {
    title: '最后更新时间',
    field: 'updateTime',
    width: 180,
    visible: false,
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 'auto',
  },
];

export const drawerSchema: FormSchemaGetter = () => [
  {
    label: '任务ID',
    fieldName: 'id',
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    label: '任务名称',
    fieldName: 'name',
    component: 'Input',
    rules: 'required',
  },
  {
    component: 'ExhibitionSelect',
    fieldName: 'exhibitionId',
    label: '所属展会',
    rules: 'selectRequired',
  },
  {
    label: '届数',
    fieldName: 'number',
    component: 'Select',
    componentProps: {
      getPopupContainer,
      options: getDictOptions(DictEnum.EXHIBITION_NUMBER, true),
    },
    rules: 'selectRequired',
  },
  {
    component: 'SmsTemplateSelect',
    fieldName: 'templateId',
    label: '短信模板',
    componentProps: {
      multiple: false,
    },
    rules: 'selectRequired',
  },
  {
    component: 'PersonalFavoriteSelect',
    fieldName: 'favoriteIds',
    label: '收件人组',
    componentProps: {
      mode: 'multiple',
    },
    defaultValue: [],
    rules: 'selectRequired',
  },
  {
    component: 'RadioGroup',
    componentProps: {
      buttonStyle: 'solid',
      options: getDictOptions(DictEnum.SMS_TASK_SEND_TYPE, true),
      optionType: 'button',
    },
    fieldName: 'sendType',
    rules: 'selectRequired',
    label: '发送类型',
  },
  {
    component: 'DatePicker',
    componentProps: {
      format: 'YYYY-MM-DD HH:mm:ss',
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
    fieldName: 'sendTime',
    label: '发送时间',
    dependencies: {
      if: (values) => values?.sendType === 1, // 定时发送
      triggerFields: ['sendType'],
    },
    rules: 'selectRequired',
  },
  {
    label: '备注',
    fieldName: 'remark',
    component: 'Textarea',
    componentProps: {
      autoSize: { minRows: 3 },
    },
  },
];

export const detailsSchema: DetailsModalSchemaGetter = () => [
  {
    label: '任务名称',
    fieldName: 'name',
    copy: true,
  },
  {
    label: '短信主题',
    fieldName: 'smsName',
    copy: true,
  },
  {
    label: '发送类型',
    fieldName: 'sendType',
    dictEnum: DictEnum.SMS_TASK_SEND_TYPE,
    dictEnumFormatNumber: true,
  },
  {
    label: '发送时间',
    fieldName: 'sendTime',
  },
  {
    label: '收件人组',
    fieldName: 'favorites',
    custom: true,
  },
  {
    label: '所属展会',
    fieldName: 'exhibitionName',
  },
  {
    label: '届数',
    fieldName: 'number',
    dictEnum: DictEnum.EXHIBITION_NUMBER,
  },
  {
    label: '备注',
    fieldName: 'remark',
    textWrap: true,
  },
];
